package com.ruix.app.ui.stratum.notice;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

import com.ruix.app.R;
import com.ruix.app.mapper.UncomfirmedUserMapper;
import com.ruix.app.model.Notice;
import com.ruix.app.model.UncomfirmedUser;
import com.ruix.app.network.RXObserver;
import com.ruix.app.network.RequestFactory;
import com.ruix.app.ui.adapter.UncomfirmUsersAdapter;
import com.ruix.app.ui.base.BaseActivity;

import java.util.ArrayList;

import io.reactivex.disposables.Disposable;

/**
 * Created by hadexs on 2017/4/23.
 */

public class ConfirmPersonActivity extends BaseActivity{


    public static Intent newIntent(Context context, Notice notice) {
        Intent intent = new Intent(context, ConfirmPersonActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable("notice", notice);
        intent.putExtras(bundle);
        return intent;
    }

    private RecyclerView recyclerView;
    private Notice notice;
    private UncomfirmUsersAdapter adapter;

    @Override
    protected int loadViewLayout() {
        return R.layout.activity_confirm_person;
    }

    @Override
    protected void initView() {
        setTitle("未确认人员");
        recyclerView =  (RecyclerView)findViewById(R.id.recycler_view);
        adapter = new UncomfirmUsersAdapter(this);
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(4, OrientationHelper.VERTICAL));
        recyclerView.setAdapter(adapter);

    }

    @Override
    protected void initLocalData() {
        Intent intent =  getIntent();
        if (intent != null) {
            notice = (Notice)intent.getSerializableExtra("notice");
        }
        loadUnconfirmUsers();
    }

    @Override
    protected void initListener() {

    }

    private void loadUnconfirmUsers(){
        showLoading();
        RequestFactory.uncomfirmUsers(notice.getId(), new UncomfirmedUserMapper(), new RXObserver<ArrayList<UncomfirmedUser>> (){

            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(ArrayList<UncomfirmedUser> value) {
                adapter.replaceAll(value);
            }

            @Override
            public void onError(Throwable e) {
                dismissLoading();
                resolveException(e);

            }

            @Override
            public void onComplete() {
                dismissLoading();
            }
        });

    }
}
